package Try;

import Try.FileUtils.FileUtil;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main28 {
    public static void main(String[] args) throws IOException {


        File file = new File("C:\\Users\\ruanjie\\Desktop\\pictureList.txt");

        File file1 = new File("C:\\Users\\ruanjie\\Desktop\\trainCloth.txt");

        File file2 = new File("C:\\Users\\ruanjie\\Desktop\\testCloth.txt");

        File file3 = new File("C:\\Users\\ruanjie\\Desktop\\trainPairs.txt");

        File file4 = new File("C:\\Users\\ruanjie\\Desktop\\testPairs.txt");

        List<String> pictureList = FileUtil.readFile(file);

        List<String> trainClothList = FileUtil.readFile(file1);

        List<String> testClothList = FileUtil.readFile(file2);

        List<String> pictureListDir = new ArrayList<>();
        List<String> trainClothListDir = new ArrayList<>();
        List<String> testClothListDir = new ArrayList<>();
        List<String> trainPairsList = new ArrayList<>();
        List<String> testPairsList = new ArrayList<>();

        for (int i=0;i<pictureList.size();i++){
            String line = pictureList.get(i).trim();
            File parent = new File((line)).getParentFile();
            pictureListDir.add(parent.getAbsolutePath().replace("F:\\JavaProject\\pictures\\",""));
        }

        for (int i=0;i<trainClothList.size();i++){
            String line = trainClothList.get(i).trim();
            File parent = new File((line)).getParentFile();
            trainClothListDir.add(parent.getAbsolutePath().replace("F:\\JavaProject\\",""));

        }

        for (int i=0;i<testClothList.size();i++){
            String line = testClothList.get(i).trim();
            File parent = new File((line)).getParentFile();
//            System.out.println(parent.getAbsoluteFile());
            testClothListDir.add(parent.getAbsolutePath().replace("F:\\JavaProject\\",""));
        }

        for (int i=0;i<pictureListDir.size();i++){
            String line = pictureListDir.get(i);
//            System.out.println(line);
            if (trainClothListDir.contains(line)){
                trainPairsList.add(pictureList.get(i).replace("pictures/","") + " " + trainClothList.get(trainClothListDir.indexOf(line)));
            }else if(testClothListDir.contains(line)){
                testPairsList.add(pictureList.get(i).replace("pictures/","") + " " + testClothList.get(testClothListDir.indexOf(line)));
            }
        }

        System.out.println(trainPairsList.size() + " " + testPairsList.size());

        FileUtil.writeToFile(file3, trainPairsList);
        FileUtil.writeToFile(file4, testPairsList);

    }
}
